package game;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class Settings {
	protected File source = new File("settings.dat");
	protected float volume;
	protected boolean musicOn;
	protected float soundVolume;
	
	public Settings(boolean o, float v, float s){
		musicOn = o;
		volume = v;
		soundVolume = s;
	}
	
	public Settings(){
		read();
	}
	
	protected void read(){
		try{
			FileInputStream fis = new FileInputStream(source);
			ObjectInputStream in = new ObjectInputStream(fis);
			musicOn = in.readBoolean();
			volume = in.readFloat();
			soundVolume = in.readFloat();
			in.close();
			fis.close();
		}catch (Exception e){
			musicOn = true;
			volume = .7f;
			soundVolume = .7f;
		}
	}
	
	protected void save(){
		ObjectOutputStream out;
		try{
			out = new ObjectOutputStream(new FileOutputStream(source));
			out.writeBoolean(musicOn);
			out.writeFloat(volume);
			out.writeFloat(soundVolume);
			out.close();
			out.close();
		}catch (Exception e){
			System.out.println("Error saving settings:  ");
			e.printStackTrace();
		}
	}
}
